/*
 * File:AbstractHandler.java
 * Type:net.wangds.common.chainofresponsibility.AbstractHandler
 */

package net.wangds.common.chainofresponsibility;

import net.wangds.common.GeneralParentObject;

/**
 * 抽象责任链处理器.
 * <p>
 * <h1>修改列表:</h1>
 * <ol>
 * <li>checkstyle, by wangds@gmail.com, 2016-01-16 下午18:13</li>
 * <li>初始版本, by wangds@gmail.com, 2013-11-7 10:08:01</li>
 * <li>wangds@gmail.com, 2013-11-27
 * <p>
 * 根据PMD插件提示，将 {@link #setNext(Handler)}方法参数设置为“final”参数。
 * </p>
 * </li>
 * </ol>
 * </p>
 * 
 * @param <E>
 *          处理过程中可能出现的异常.
 * @param <H>
 *          责任链类型.
 * @author wangds@gmail.com
 * @version 0.1.2
 * @since 0.1
 */
public abstract class AbstractHandler extends GeneralParentObject implements Handler {

  /**
   * 责任链中下一个处理器.
   */
  private Handler next;

  @SuppressWarnings("unchecked")
  @Override
  public <H extends Handler> H getNext() {
    return (H) this.next;
  }

  @Override
  public <H extends Handler> void setNext(final H theNext) {
    this.next = theNext;
  }

  @Override
  public void process() throws Exception {
    if (this.handle() && this.next != null) {
      this.next.process();
    }
  }

}
